#include <iostream>
#include "comm.hpp"

int main()
{   
    std::string query_string;
    GetQueryString(query_string);
    
    std::string str1, str2;
    CutString(query_string, "&", str1, str2);

    std::string name1, value1;
    CutString(str1, "=", name1, value1);

    std::string name2, value2;
    CutString(str2, "=", name2, value2);

    // 1 
    std::cout << name1 << " : " << value1 << std::endl;
    std::cout << name2 << " : " << value2 << std::endl;
    // 2
    std::cerr << name1 << " : " << value1 << std::endl;
    std::cerr << name2 << " : " << value2 << std::endl;

    // 可能想进行某种计算（运算，搜索，登录）
    int x = atoi(value1.c_str());
    int y = atoi(value2.c_str());
    std::cout << "<html>";
    std::cout << "<head><meta charset=\"utf-8\"></head>";
    std::cout << "<body>";
    std::cout << "<h3> " << value1 << " + " << value2 << " = " << x + y << "</h3>";
    std::cout << "<h3> " << value1 << " - " << value2 << " = " << x - y << "</h3>";
    std::cout << "<h3> " << value1 << " * " << value2 << " = " << x * y << "</h3>";
    if (y != 0) {
        std::cout << "<h3> " << value1 << " / " << value2 << " = " << x / y << "</h3>";
    } else {
        std::cout << "<h3> " << value1 << " / " << value2 << " = 错误：除数不能为零</h3>";
    }
    std::cout << "</body>";
    std::cout << "</html>";

    return 0;
}